package aupdg.presentation;

import aupdg.data.Log;
import aupdg.data.model.Edge;
import aupdg.data.model.Ldg;
import aupdg.data.model.Node;
import aupdg.data.model.Petrinet;
import aupdg.data.model.impl.AuDataDependenceEdge;
import aupdg.data.wrapper.ProMLog;
import aupdg.debug.PetriNetDebugger;
import aupdg.logic.analysis.SecurityLevel;
import aupdg.logic.analysis.impl.ExplicitILAnalysis;
import aupdg.logic.analysis.impl.ImplicitILAnalysis;
import aupdg.logic.analysis.impl.NonInterferenceAnalysis;
import aupdg.logic.exceptions.LoopsException;
import aupdg.logic.impl.LdgAlgorithmForProM;
import aupdg.logic.mining.AlphaAlgorithm;
import aupdg.logic.mining.wrapper.ProMAlphaPP;
import aupdg.presentation.adapter.impl.LdgToJPanelImpl;
import com.jgoodies.looks.plastic.Plastic3DLookAndFeel;
import edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse;
import edu.uci.ics.jung.visualization.control.ModalGraphMouse;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import org.processmining.analysis.decisionmining.DecisionPointAnalysisResultForAuLdg;
import org.processmining.framework.log.LogReader;
import org.processmining.framework.log.LogReaderException;
import org.processmining.framework.models.hlprocess.hlmodel.HLPetriNet;
import org.processmining.framework.models.petrinet.PetriNet;

/**
 * GUI of AuLDG.
 *
 * @author AA and CJ
 */
public class MainGUI extends JFrame {

    private DataBean dataBean;
    private Petrinet petrinet;
    private Log myLog;
    private Ldg myLdg;
    public JMenu modeMenu;
    public DefaultModalGraphMouse gm;
    private DefaultTableModel logTableData;
    //Models for lists in logPanel
    private DefaultListModel modelInstances;
    private DefaultListModel modelEvents;
    private DecisionPointAnalysisResultForAuLdg dataMiningPanel;
    private DefaultListModel modelInput;
    private DefaultListModel modelOutput;
    private DefaultListModel modelOther;
    private SelectionListener niListener;
    private SelectionListener exiListener;
    private SelectionListener imiListener;
    private NodeEdgePopupMousePlugin popupPlugin;
    private boolean selectionListenerAssigned = false;

    /**
     * Creates new form mainFrame. Uses the DataBean object to fill the panels
     * with information from the event log.
     *
     * @param data
     */
    public MainGUI(DataBean data) {
        try {
            UIManager.setLookAndFeel(new Plastic3DLookAndFeel());
        } catch (Exception e) {
            System.out.println(e);
        }
        logTableData = new DefaultTableModel();
        logTableData.addColumn("Instance");
        logTableData.addColumn("Event");
        logTableData.addColumn("Input");
        logTableData.addColumn("Output");

        modelInstances = new DefaultListModel();
        initComponents();
        gm = new DefaultModalGraphMouse();

        //Popup menus for nodes and edges
        popupPlugin = new NodeEdgePopupMousePlugin();
        JPopupMenu nodeMenu = new NodePopupMenu();
        JPopupMenu edgeMenu = new EdgePopupMenu();

        this.add(nodeMenu);
        this.add(edgeMenu);

        popupPlugin.setNodeMenu(nodeMenu);
        popupPlugin.setEdgeMenu(edgeMenu);
        gm.add(popupPlugin);


        gm.setMode(ModalGraphMouse.Mode.TRANSFORMING);

        SampleLdgToJPanelImpl samplePanelLdg = new SampleLdgToJPanelImpl(gm);
        JPanel sampleZoomPanel = samplePanelLdg.renderLdg();
        sampleZoomPanel.setVisible(true);
        sampleZoomPanel.revalidate();
        sampleZoomPanel.repaint();

        pGraph.setLayout(new BorderLayout());
        pGraph.add(sampleZoomPanel, BorderLayout.CENTER);
        pGraph.revalidate();
        pGraph.repaint();

        modeMenu = gm.getModeMenu();
        modeMenu.setText("Mouse Mode");
        modeMenu.setPreferredSize(new Dimension(80, 20));
        modeMenu.setIcon(null);
        menuBar.add(modeMenu);
        this.dataBean = data;
        fileChooser.setVisible(false);
        tLogTable.setModel(logTableData);

        getContentPane().setBackground(Color.BLACK);
    }

    /**
     * This method initializes all the components. This method is called from
     * within the constructor to initialize the form. WARNING: Do NOT modify
     * this code. The content of this method is always regenerated by the Form
     * Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btngMouseMode = new javax.swing.ButtonGroup();
        logFrame = new javax.swing.JFrame();
        logTopPanel = new javax.swing.JPanel();
        lblFlogNumInstances = new javax.swing.JLabel();
        lblFlogTotalNumEvents = new javax.swing.JLabel();
        lblFlogNumOriginators = new javax.swing.JLabel();
        lblFlogNumLogEvents = new javax.swing.JLabel();
        lblFlogNumInstancesRes = new javax.swing.JLabel();
        lblFlogTotalNumEventsRes = new javax.swing.JLabel();
        lblFlogNumLogEventsRes = new javax.swing.JLabel();
        lblFlogNumOriginatorsRes = new javax.swing.JLabel();
        logTabbedPane = new javax.swing.JTabbedPane();
        pLogTableTab = new javax.swing.JPanel();
        jScrollPane6 = new javax.swing.JScrollPane();
        tLogTable = new javax.swing.JTable();
        pLogBrowserTab = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        lstPlogBrowserInstances = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        lstPlogBrowserEvents = new javax.swing.JList();
        jScrollPane3 = new javax.swing.JScrollPane();
        lstPlogBrowserInputs = new javax.swing.JList();
        jScrollPane4 = new javax.swing.JScrollPane();
        lstPlogBrowserOutputs = new javax.swing.JList();
        jScrollPane5 = new javax.swing.JScrollPane();
        lstPlogBrowserOtherAttr = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        fileChooser = new javax.swing.JFileChooser();
        pLogSummary = new javax.swing.JPanel(){
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                // Draw the background image.
                try{
                    g.drawImage(ImageIO.read(this.getClass().getClassLoader().getResource("aupdg/presentation/resources/topPanelBackground.png")), 0, 0, null);
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
        };
        lblFile = new javax.swing.JLabel();
        lblFileRes = new javax.swing.JLabel();
        pGraph = new javax.swing.JPanel(){
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                // Draw the background image.
                try{
                    g.drawImage(ImageIO.read(this.getClass().getClassLoader().getResource("aupdg/presentation/resources/graphPanelBackground.png")), 0, 0, null);
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
        };
        pAnalysisSummary = new javax.swing.JPanel(){
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                // Draw the background image.
                try{
                    g.drawImage(ImageIO.read(this.getClass().getClassLoader().getResource("aupdg/presentation/resources/westBackground.png")), 0, 0, null);
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
        };
        lblExplicitInfLeaks = new javax.swing.JLabel();
        lblImplicitInfLeaks = new javax.swing.JLabel();
        lblNonInterference = new javax.swing.JLabel();
        jScrollPane7 = new javax.swing.JScrollPane();
        nonInterferenceTable = new javax.swing.JTable();
        jScrollPane8 = new javax.swing.JScrollPane();
        explicitILTable = new javax.swing.JTable();
        jScrollPane9 = new javax.swing.JScrollPane();
        implicitILTable = new javax.swing.JTable();
        btnAnalysis = new javax.swing.JButton();
        btnImport = new javax.swing.JButton();
        btnGenerateLDG = new javax.swing.JButton();
        lblProcInstances = new javax.swing.JLabel();
        lblProcInstancesRes = new javax.swing.JLabel();
        lblEvents = new javax.swing.JLabel();
        lblEventsRes = new javax.swing.JLabel();
        lblDecisionPoints = new javax.swing.JLabel();
        lblDecisionPointsRes = new javax.swing.JLabel();
        pAnalysisDetails = new javax.swing.JTabbedPane();
        legendLabel = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar(){
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                // Draw the background image.
                try{
                    g.drawImage(ImageIO.read(this.getClass().getClassLoader().getResource("aupdg/presentation/resources/menuPanelBackground.png")), 0, 0, null);
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
        };
        mLog = new javax.swing.JMenu();
        mItImportEventLog = new javax.swing.JMenuItem();
        mItLogPanel = new javax.swing.JMenuItem();

        logFrame.setTitle("L1.mxml");
        logFrame.setBounds(new java.awt.Rectangle(0, 0, 800, 600));

        lblFlogNumInstances.setText("Number of Instances:");

        lblFlogTotalNumEvents.setText("Total Number of Events:");

        lblFlogNumOriginators.setText("Number of Originators:");

        lblFlogNumLogEvents.setText("Number of Log Events:");

        lblFlogNumInstancesRes.setText("0");

        lblFlogTotalNumEventsRes.setText("0");

        lblFlogNumLogEventsRes.setText("0");

        lblFlogNumOriginatorsRes.setText("0");

        javax.swing.GroupLayout logTopPanelLayout = new javax.swing.GroupLayout(logTopPanel);
        logTopPanel.setLayout(logTopPanelLayout);
        logTopPanelLayout.setHorizontalGroup(
            logTopPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(logTopPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(logTopPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(lblFlogNumInstances)
                    .addComponent(lblFlogTotalNumEvents))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(logTopPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lblFlogNumInstancesRes, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE)
                    .addComponent(lblFlogTotalNumEventsRes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(44, 44, 44)
                .addGroup(logTopPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblFlogNumLogEvents, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblFlogNumOriginators, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(logTopPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lblFlogNumLogEventsRes, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE)
                    .addComponent(lblFlogNumOriginatorsRes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        logTopPanelLayout.setVerticalGroup(
            logTopPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(logTopPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(logTopPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblFlogNumInstances)
                    .addComponent(lblFlogNumLogEvents)
                    .addComponent(lblFlogNumInstancesRes)
                    .addComponent(lblFlogNumLogEventsRes))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(logTopPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblFlogTotalNumEvents)
                    .addComponent(lblFlogNumOriginators)
                    .addComponent(lblFlogTotalNumEventsRes)
                    .addComponent(lblFlogNumOriginatorsRes))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        tLogTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane6.setViewportView(tLogTable);

        javax.swing.GroupLayout pLogTableTabLayout = new javax.swing.GroupLayout(pLogTableTab);
        pLogTableTab.setLayout(pLogTableTabLayout);
        pLogTableTabLayout.setHorizontalGroup(
            pLogTableTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pLogTableTabLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 535, Short.MAX_VALUE)
                .addContainerGap())
        );
        pLogTableTabLayout.setVerticalGroup(
            pLogTableTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pLogTableTabLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                .addContainerGap())
        );

        logTabbedPane.addTab("Table", pLogTableTab);

        lstPlogBrowserInstances.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        lstPlogBrowserInstances.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lstPlogBrowserInstancesMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(lstPlogBrowserInstances);

        jScrollPane2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jScrollPane2MouseClicked(evt);
            }
        });

        lstPlogBrowserEvents.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        lstPlogBrowserEvents.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lstPlogBrowserEventsMouseClicked(evt);
            }
        });
        lstPlogBrowserEvents.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                lstPlogBrowserEventsValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(lstPlogBrowserEvents);

        lstPlogBrowserInputs.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane3.setViewportView(lstPlogBrowserInputs);

        lstPlogBrowserOutputs.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane4.setViewportView(lstPlogBrowserOutputs);

        lstPlogBrowserOtherAttr.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane5.setViewportView(lstPlogBrowserOtherAttr);

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Case");

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("Event");

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("Input");

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel4.setText("Output");

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel5.setText("Attributes");

        javax.swing.GroupLayout pLogBrowserTabLayout = new javax.swing.GroupLayout(pLogBrowserTab);
        pLogBrowserTab.setLayout(pLogBrowserTabLayout);
        pLogBrowserTabLayout.setHorizontalGroup(
            pLogBrowserTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pLogBrowserTabLayout.createSequentialGroup()
                .addGroup(pLogBrowserTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pLogBrowserTabLayout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pLogBrowserTabLayout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pLogBrowserTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pLogBrowserTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 14, Short.MAX_VALUE))
        );
        pLogBrowserTabLayout.setVerticalGroup(
            pLogBrowserTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pLogBrowserTabLayout.createSequentialGroup()
                .addGroup(pLogBrowserTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pLogBrowserTabLayout.createSequentialGroup()
                        .addGroup(pLogBrowserTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3))
                        .addGap(1, 1, 1))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pLogBrowserTabLayout.createSequentialGroup()
                        .addGroup(pLogBrowserTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(pLogBrowserTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 361, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 21, Short.MAX_VALUE))
        );

        logTabbedPane.addTab("Browser", pLogBrowserTab);

        javax.swing.GroupLayout logFrameLayout = new javax.swing.GroupLayout(logFrame.getContentPane());
        logFrame.getContentPane().setLayout(logFrameLayout);
        logFrameLayout.setHorizontalGroup(
            logFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(logTopPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(logFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(logTabbedPane, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
        );
        logFrameLayout.setVerticalGroup(
            logFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(logFrameLayout.createSequentialGroup()
                .addComponent(logTopPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(logTabbedPane))
        );

        fileChooser.setDialogTitle("Import Event Log File");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("AuLDG");
        setBackground(new java.awt.Color(255, 255, 255));
        setMaximumSize(new java.awt.Dimension(1420, 780));

        pLogSummary.setMaximumSize(new java.awt.Dimension(1920, 300));

        lblFile.setFont(lblFile.getFont());
        lblFile.setForeground(new java.awt.Color(255, 51, 51));
        lblFile.setText("File:");

        javax.swing.GroupLayout pLogSummaryLayout = new javax.swing.GroupLayout(pLogSummary);
        pLogSummary.setLayout(pLogSummaryLayout);
        pLogSummaryLayout.setHorizontalGroup(
            pLogSummaryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pLogSummaryLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblFile, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(lblFileRes, javax.swing.GroupLayout.DEFAULT_SIZE, 753, Short.MAX_VALUE)
                .addContainerGap())
        );
        pLogSummaryLayout.setVerticalGroup(
            pLogSummaryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pLogSummaryLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pLogSummaryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pLogSummaryLayout.createSequentialGroup()
                        .addComponent(lblFile)
                        .addGap(0, 16, Short.MAX_VALUE))
                    .addGroup(pLogSummaryLayout.createSequentialGroup()
                        .addComponent(lblFileRes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())))
        );

        pGraph.setBackground(new java.awt.Color(255, 255, 255));
        pGraph.setAutoscrolls(true);
        pGraph.setMaximumSize(new java.awt.Dimension(1420, 780));
        pGraph.setPreferredSize(new java.awt.Dimension(0, 400));
        pGraph.setVerifyInputWhenFocusTarget(false);

        javax.swing.GroupLayout pGraphLayout = new javax.swing.GroupLayout(pGraph);
        pGraph.setLayout(pGraphLayout);
        pGraphLayout.setHorizontalGroup(
            pGraphLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 818, Short.MAX_VALUE)
        );
        pGraphLayout.setVerticalGroup(
            pGraphLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        pAnalysisSummary.setMaximumSize(new java.awt.Dimension(500, 780));
        pAnalysisSummary.setPreferredSize(new java.awt.Dimension(301, 400));

        lblExplicitInfLeaks.setForeground(new java.awt.Color(255, 255, 255));
        lblExplicitInfLeaks.setText("Explicit Information Leaks:");

        lblImplicitInfLeaks.setForeground(new java.awt.Color(255, 255, 255));
        lblImplicitInfLeaks.setText("Implicit Information Leaks:");

        lblNonInterference.setForeground(new java.awt.Color(255, 255, 255));
        lblNonInterference.setText("Noninterference:");

        nonInterferenceTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Originators"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        nonInterferenceTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        nonInterferenceTable.setShowHorizontalLines(false);
        nonInterferenceTable.setShowVerticalLines(false);
        jScrollPane7.setViewportView(nonInterferenceTable);

        explicitILTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Originators"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        explicitILTable.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        explicitILTable.setShowHorizontalLines(false);
        explicitILTable.setShowVerticalLines(false);
        jScrollPane8.setViewportView(explicitILTable);

        implicitILTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Originators"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        implicitILTable.setShowHorizontalLines(false);
        implicitILTable.setShowVerticalLines(false);
        jScrollPane9.setViewportView(implicitILTable);

        btnAnalysis.setIcon(new javax.swing.ImageIcon(getClass().getResource("/aupdg/presentation/resources/leaksBtn.png"))); // NOI18N
        btnAnalysis.setBorder(null);
        btnAnalysis.setBorderPainted(false);
        btnAnalysis.setContentAreaFilled(false);
        btnAnalysis.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/aupdg/presentation/resources/leaksBtnRO.png"))); // NOI18N
        btnAnalysis.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnAnalysisMouseClicked(evt);
            }
        });

        btnImport.setIcon(new javax.swing.ImageIcon(getClass().getResource("/aupdg/presentation/resources/importFileBtn.png"))); // NOI18N
        btnImport.setBorder(null);
        btnImport.setBorderPainted(false);
        btnImport.setContentAreaFilled(false);
        btnImport.setName(""); // NOI18N
        btnImport.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/aupdg/presentation/resources/importFileBtnRO.png"))); // NOI18N
        btnImport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnImportActionPerformed(evt);
            }
        });

        btnGenerateLDG.setIcon(new javax.swing.ImageIcon(getClass().getResource("/aupdg/presentation/resources/generateBtn.png"))); // NOI18N
        btnGenerateLDG.setBorder(null);
        btnGenerateLDG.setBorderPainted(false);
        btnGenerateLDG.setContentAreaFilled(false);
        btnGenerateLDG.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/aupdg/presentation/resources/generateBtnRO.png"))); // NOI18N
        btnGenerateLDG.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGenerateLDGActionPerformed(evt);
            }
        });

        lblProcInstances.setFont(lblProcInstances.getFont());
        lblProcInstances.setForeground(new java.awt.Color(255, 51, 51));
        lblProcInstances.setText("Processes Instances:");

        lblProcInstancesRes.setFont(lblProcInstancesRes.getFont());
        lblProcInstancesRes.setForeground(new java.awt.Color(255, 255, 255));
        lblProcInstancesRes.setText("0");

        lblEvents.setFont(lblEvents.getFont());
        lblEvents.setForeground(new java.awt.Color(255, 51, 51));
        lblEvents.setText("Events:");

        lblEventsRes.setFont(lblEventsRes.getFont());
        lblEventsRes.setForeground(new java.awt.Color(255, 255, 255));
        lblEventsRes.setText("0");

        lblDecisionPoints.setFont(lblDecisionPoints.getFont());
        lblDecisionPoints.setForeground(new java.awt.Color(255, 51, 51));
        lblDecisionPoints.setText("Decision Points:");

        lblDecisionPointsRes.setFont(lblDecisionPointsRes.getFont());
        lblDecisionPointsRes.setForeground(new java.awt.Color(255, 255, 255));
        lblDecisionPointsRes.setText("0");

        javax.swing.GroupLayout pAnalysisSummaryLayout = new javax.swing.GroupLayout(pAnalysisSummary);
        pAnalysisSummary.setLayout(pAnalysisSummaryLayout);
        pAnalysisSummaryLayout.setHorizontalGroup(
            pAnalysisSummaryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pAnalysisSummaryLayout.createSequentialGroup()
                .addGroup(pAnalysisSummaryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane9, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(pAnalysisSummaryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pAnalysisSummaryLayout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(btnImport)
                            .addGap(18, 18, 18)
                            .addComponent(btnGenerateLDG))
                        .addGroup(pAnalysisSummaryLayout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(pAnalysisSummaryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(lblImplicitInfLeaks)
                                .addComponent(lblExplicitInfLeaks)
                                .addComponent(lblNonInterference)))
                        .addGroup(pAnalysisSummaryLayout.createSequentialGroup()
                            .addGap(28, 28, 28)
                            .addGroup(pAnalysisSummaryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(pAnalysisSummaryLayout.createSequentialGroup()
                                    .addComponent(lblProcInstances)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(lblProcInstancesRes, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(pAnalysisSummaryLayout.createSequentialGroup()
                                    .addComponent(lblEvents)
                                    .addGap(18, 18, 18)
                                    .addComponent(lblEventsRes, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(pAnalysisSummaryLayout.createSequentialGroup()
                                    .addComponent(lblDecisionPoints)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(lblDecisionPointsRes, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGroup(pAnalysisSummaryLayout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(btnAnalysis, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pAnalysisSummaryLayout.setVerticalGroup(
            pAnalysisSummaryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pAnalysisSummaryLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pAnalysisSummaryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnImport, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnGenerateLDG, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnAnalysis, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(pAnalysisSummaryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblProcInstances)
                    .addComponent(lblProcInstancesRes))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pAnalysisSummaryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblEvents)
                    .addComponent(lblEventsRes))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pAnalysisSummaryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDecisionPoints)
                    .addComponent(lblDecisionPointsRes))
                .addGap(18, 18, 18)
                .addComponent(lblNonInterference)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(lblExplicitInfLeaks)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(lblImplicitInfLeaks)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane9, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        legendLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/aupdg/presentation/resources/legend.png"))); // NOI18N
        pAnalysisDetails.addTab("Legend", legendLabel);

        menuBar.setBackground(new java.awt.Color(255, 255, 255));

        mLog.setText("Log");

        mItImportEventLog.setText("Import Event Log");
        mItImportEventLog.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mItImportEventLogActionPerformed(evt);
            }
        });
        mLog.add(mItImportEventLog);

        mItLogPanel.setText("Log Panel");
        mItLogPanel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mItLogPanelActionPerformed(evt);
            }
        });
        mLog.add(mItLogPanel);

        menuBar.add(mLog);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pAnalysisSummary, 298, 298, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pLogSummary, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pGraph, javax.swing.GroupLayout.DEFAULT_SIZE, 818, Short.MAX_VALUE)
                    .addComponent(pAnalysisDetails)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pLogSummary, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pGraph, javax.swing.GroupLayout.DEFAULT_SIZE, 472, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pAnalysisDetails, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(pAnalysisSummary, javax.swing.GroupLayout.DEFAULT_SIZE, 646, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Implements the action of the import button
     *
     * @param evt
     */
    private void btnImportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImportActionPerformed
        String[][] rowData;
        fileChooser.setVisible(true);
        //TODO file filter, to choose only .txt and .mxml files
        int returnVal = fileChooser.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fileChooser.getSelectedFile();
            try {
                dataBean = new DataBean();
                dataBean.setPathToFile(fileChooser.getSelectedFile().getPath());

                System.out.println("file selected: " + file.getAbsolutePath());

                //String pathTofile = "D:/Documents/Uni/Materias/3_Semestre/TeamProject_AuditProgramDependenceGraph/event-logs-process-mining-book/Chapter_5/L1.mxml";
                myLog = new ProMLog(dataBean);

                if (dataBean.hasLoops()) {
                    throw new LoopsException();
                }

                AlphaAlgorithm alg = new ProMAlphaPP();
                petrinet = alg.mine(myLog);

                //Optional: it prints information about the log in the console
                PetriNetDebugger pnd = new PetriNetDebugger(petrinet);
                pnd.print_info();


                LdgAlgorithmForProM alg2 = new LdgAlgorithmForProM(myLog);
                //OR
                //LdgAlgorithm alg2 = new LdgAlgorithmForProMDebug();
                myLdg = alg2.generateLdg(petrinet);
                //Ldg ldg2 = alg2.getLdg2();
                //System.out.println("************LDG2****************");
                //System.out.println(ldg2.asString());
                Integer numberOfDecisionPoints = myLdg.getIfNodes().size();

                //Change values of labels in main frame
                lblFileRes.setText(dataBean.getPathToFile());
                lblFileRes.setForeground(Color.white);
                lblProcInstancesRes.setText(String.valueOf(dataBean.getNumProcessInstances()));
                lblEventsRes.setText(String.valueOf(dataBean.getNumLogEvents()));
                lblDecisionPointsRes.setText(numberOfDecisionPoints.toString());

                logTableData.setRowCount(dataBean.getLogTableData().length);

                //set Values in logTable                                
                for (int i = 0; i < dataBean.getLogTableData().length; i++) {
                    rowData = dataBean.getLogTableData();
                    //logTableData.addRow(rowData[i]);
                    for (int j = 0; j < rowData[i].length; j++) {
                        logTableData.setValueAt(rowData[i][j], i, j);
                    }
                }
                lblFlogNumInstancesRes.setText(String.valueOf(dataBean.getNumProcessInstances()));
                lblFlogNumLogEventsRes.setText(String.valueOf(dataBean.getNumLogEvents()));
                lblFlogTotalNumEventsRes.setText(String.valueOf(dataBean.getNumTotalEvents()));
                lblFlogNumOriginatorsRes.setText(String.valueOf(dataBean.getNumOriginators()));

                //Values for tab Browser in logPanel
                modelInstances = new DefaultListModel();
                modelEvents = new DefaultListModel();
                modelInput = new DefaultListModel();
                modelOutput = new DefaultListModel();
                modelOther = new DefaultListModel();

                for (int i = 0; i < dataBean.getInstances().size(); i++) {
                    modelInstances.add(i, dataBean.getInstances().get(i));
                }

                //Instances
//                for(int i=0; i<dataBean.getInstanceKeyValue().size(); i++){
//                    modelInstances.add(i,dataBean.getInstanceKeyValue().get(i));
//                }
//                //Events for first instance in the list
//                for(int i=0; i<dataBean.getMapInstanceEventKeys().get(0).size(); i++){
//                    modelEvents.add(i, dataBean.getEventKeyValues().get(dataBean.getMapInstanceEventKeys().get(0).get(i)));
//                }
//                //Input attributes of first event and instance
//                for(int i=0; i<dataBean.getMapEventAtrrInputKeys().get(0).size(); i++){
//                    ArrayList<Integer> firstInstance = new ArrayList<Integer>();
//                    firstInstance = dataBean.getMapInstanceEventKeys().get(0);
//                    modelInput.add(i, dataBean.getAttrInputValue(dataBean.getMapEventAtrrInputKeys().get(firstInstance.get(0)).get(i)));   
//                }

                lstPlogBrowserInstances.setModel(modelInstances);
                lstPlogBrowserEvents.setModel(modelEvents);
                lstPlogBrowserInputs.setModel(modelInput);

                System.out.println("flog; " + logFrame);
                logFrame.setTitle(file.getAbsolutePath());
                logFrame.setVisible(true);

                System.out.println("isPreferredSizeSet " + logFrame.isPreferredSizeSet());

//                System.out.println("instance key value "+dataBean.getInstanceKeyValue().toString());
//                System.out.println("event key value "+dataBean.getEventKeyValues().toString());
//                System.out.println("map instance event "+dataBean.getMapInstanceEventKeys().toString());
//                System.out.println("input attributes: ");
//                System.out.println("input key value "+dataBean.getMapEventAtrrInputKeys().toString());
//              
                pGraph.removeAll();
                resetAnalysisPanel();

            } catch (LogReaderException e) {
                JOptionPane.showMessageDialog(this,
                        "Bad formed MXML or format not supported.",
                        "Parser error",
                        JOptionPane.ERROR_MESSAGE);
                System.out.println("bad format: file " + file.getAbsolutePath());
                //e.printStackTrace();
            } catch (LoopsException e) {
                JOptionPane.showMessageDialog(this,
                        "Log contains loops. Not supported.",
                        "Parser error",
                        JOptionPane.ERROR_MESSAGE);
                System.out.println("bad format: file " + file.getAbsolutePath());
                //e.printStackTrace();
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this,
                        "Ooops.. try again!",
                        "Generic error",
                        JOptionPane.ERROR_MESSAGE);
                //ex.printStackTrace();
                Logger.getLogger(MainGUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            System.out.println("File access cancelled by user.");
        }

    }//GEN-LAST:event_btnImportActionPerformed

    private void mItImportEventLogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mItImportEventLogActionPerformed
        // TODO add your handling code here:
        btnImport.doClick();
    }//GEN-LAST:event_mItImportEventLogActionPerformed
    /**
     * Implements the action of the button "Generate LDG".
     *
     * @param evt
     */
    private void btnGenerateLDGActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGenerateLDGActionPerformed

        //We create the dataMining resources
        if (petrinet == null) {
            JOptionPane.showMessageDialog(this,
                    "You have to load first a MXML log file");
        } else {

            PetriNet petriNet = (PetriNet) petrinet.getInnerPetriNet();
            HLPetriNet hl = new HLPetriNet(petriNet);

            pGraph.removeAll();

            //Rendering of Ldg
            //LdgToDirectedGraph converter = new  LdgToDirectedGraphImpl();
            //DirectedGraph<Node,Edge> graph = converter.convert(myLdg); //porque aqui y en renderLdg otra vez?
            //LdgToJFrame converter2 = new  LdgToJFrameImpl();
            LdgToJPanelImpl panelLdg = null;
            panelLdg = new LdgToJPanelImpl(myLdg, gm);
            JPanel zoomPanel = panelLdg.renderLdg();
            zoomPanel.setVisible(true);
            zoomPanel.revalidate();
            zoomPanel.repaint();

            pGraph.add(zoomPanel, BorderLayout.CENTER);
            pGraph.revalidate();
            pGraph.repaint();

            //Data mining component. Redraws the LDG to add decision mining information
            JFrame dataMiningFrame = new JFrame("PROM :: Decision Mining");
            //dataMiningFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            dataMiningPanel = new DecisionPointAnalysisResultForAuLdg(hl, petriNet,
                    (LogReader) myLog.getInnerLog(), myLdg, dataMiningFrame, pGraph, gm);
            dataMiningFrame.getContentPane().add(dataMiningPanel);
            dataMiningFrame.pack();
            resetAnalysisPanel();
            //panelLdg.setVisible(true);
            //JFrame frame = new JFrame();
            //panelLdg.setSize(panelLdg.getParent().getSize());
            //frame.add(panelLdg);
            //frame.validate();
            //frame.setVisible(true);
        }
    }//GEN-LAST:event_btnGenerateLDGActionPerformed

    private void mItLogPanelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mItLogPanelActionPerformed

        logFrame.setVisible(true);
    }//GEN-LAST:event_mItLogPanelActionPerformed

    private void lstPlogBrowserInstancesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstPlogBrowserInstancesMouseClicked
        int instanceIndex;
        List<String> eventsFromInstance;

        instanceIndex = lstPlogBrowserInstances.getSelectedIndex();
        modelEvents = new DefaultListModel();
        eventsFromInstance = dataBean.getEventsFromInstance(String.valueOf(lstPlogBrowserInstances.getModel().getElementAt(instanceIndex)));
        for (int i = 0; i < eventsFromInstance.size(); i++) {
            modelEvents.add(i, eventsFromInstance.get(i));
        }
//        for(int i=0; i<dataBean.getMapInstanceEventKeys().get(instanceIndex).size(); i++){
//            modelEvents.add(i, dataBean.getEventValue(dataBean.getMapInstanceEventKeys().get(instanceIndex).get(i)));
//        }
        lstPlogBrowserEvents.setModel(modelEvents);
//        if(evt.getComponent().equals(lstPlogBrowserInstances)){
//            if(lstPlogBrowserInstances.getSelectedIndex()==1){
//                modelInstances.addElement("sel1");
//            }else{
//                modelInstances.addElement("selelse");
//            }
//        }
    }//GEN-LAST:event_lstPlogBrowserInstancesMouseClicked

    private void lstPlogBrowserEventsValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_lstPlogBrowserEventsValueChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_lstPlogBrowserEventsValueChanged

    private void jScrollPane2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jScrollPane2MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jScrollPane2MouseClicked

    private void lstPlogBrowserEventsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstPlogBrowserEventsMouseClicked
        // TODO add your handling code here:
        int instanceIndex;
        int eventIndex;
        List<List<String>> attributes = new ArrayList<>();
        modelInput = new DefaultListModel();
        modelOutput = new DefaultListModel();
        modelOther = new DefaultListModel();


        instanceIndex = lstPlogBrowserInstances.getSelectedIndex();
        eventIndex = lstPlogBrowserEvents.getSelectedIndex();

        System.out.println("Instance: " + lstPlogBrowserInstances.getModel().getElementAt(instanceIndex));
        System.out.println("Event: " + lstPlogBrowserEvents.getModel().getElementAt(eventIndex));
        attributes = dataBean.getAttrFromEvent(String.valueOf(lstPlogBrowserInstances.getModel().getElementAt(instanceIndex)), String.valueOf(lstPlogBrowserEvents.getModel().getElementAt(eventIndex)));
        for (int i = 0; i < attributes.get(0).size(); i++) {
            modelInput.addElement(attributes.get(0).get(i));
        }
        for (int i = 0; i < attributes.get(1).size(); i++) {
            modelOutput.addElement(attributes.get(1).get(i));
        }
        for (int i = 0; i < attributes.get(2).size(); i++) {
            modelOther.addElement(attributes.get(2).get(i));
        }
        lstPlogBrowserInputs.setModel(modelInput);
        lstPlogBrowserOutputs.setModel(modelOutput);
        lstPlogBrowserOtherAttr.setModel(modelOther);
    }//GEN-LAST:event_lstPlogBrowserEventsMouseClicked
    /**
     * Implements the action of the button "Information Leak Analysis".
     *
     * @param evt
     */
    private void btnAnalysisMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnAnalysisMouseClicked
        if (petrinet == null) {
            JOptionPane.showMessageDialog(this,
                    "You have to load first a MXML log file");
        } else {
            resetAnalysisPanel();
            // TODO add your handling code here:
            //Test tt = new Test();
            NonInterferenceAnalysis niAnalysis = new NonInterferenceAnalysis(myLdg);
            ExplicitILAnalysis eilAnalysis = new ExplicitILAnalysis(myLdg);
            ImplicitILAnalysis iilAnalysis = new ImplicitILAnalysis(myLdg);

            Map niResults = niAnalysis.detectInformationLeaks();
            Map eilResults = eilAnalysis.detectInformationLeaks();
            Map iilResults = iilAnalysis.detectInformationLeaks();

            if (!selectionListenerAssigned) {
                niListener = new SelectionListener("NI", pAnalysisDetails, nonInterferenceTable, niResults);
                nonInterferenceTable.getSelectionModel().addListSelectionListener(niListener);
                exiListener = new SelectionListener("EX", pAnalysisDetails, explicitILTable, eilResults);
                explicitILTable.getSelectionModel().addListSelectionListener(exiListener);
                imiListener = new SelectionListener("IM", pAnalysisDetails, implicitILTable, iilResults);
                implicitILTable.getSelectionModel().addListSelectionListener(imiListener);
                selectionListenerAssigned = true;
            } else {
                niListener.setInnerMap(niResults);
                exiListener.setInnerMap(eilResults);
                imiListener.setInnerMap(iilResults);
            }

            boolean atLeastOnNodeIsHigh = false;
            List<Node> tNodes = myLdg.getTransitionNodes();
            List<Node> ifNodes = myLdg.getIfNodes();
            List<Node> pNodes = myLdg.getPredicateNodes();
            List<Edge> dDepEdge = myLdg.getDataDepEdges();

            for (int i = 0; i < tNodes.size(); i++) {
                if (tNodes.get(i).getLevel() == SecurityLevel.HIGH) {
                    atLeastOnNodeIsHigh = true;
                }
            }

            for (int i = 0; i < ifNodes.size(); i++) {
                if (ifNodes.get(i).getLevel() == SecurityLevel.HIGH) {
                    atLeastOnNodeIsHigh = true;
                }
            }

            for (int i = 0; i < pNodes.size(); i++) {
                if (pNodes.get(i).getLevel() == SecurityLevel.HIGH) {
                    atLeastOnNodeIsHigh = true;
                }
            }
            for (int i = 0; i < dDepEdge.size(); i++) {
                AuDataDependenceEdge dataDepEdge = (AuDataDependenceEdge) dDepEdge.get(i);
                for (int j = 0; j < dataDepEdge.getDataObjects().size(); j++) {
                    if (dataDepEdge.getDataObjects().get(j).getSecurityLevel() == SecurityLevel.HIGH) {
                        atLeastOnNodeIsHigh = true;
                    }
                }
            }
            if (atLeastOnNodeIsHigh) {
                fillTableWithILFindings(nonInterferenceTable, niResults);
            } else {
                JOptionPane.showMessageDialog(this,
                        "At least one node or edge must have high security level");
            }
            fillTableWithILFindings(explicitILTable, eilResults);
            fillTableWithILFindings(implicitILTable, iilResults);
        }
    }//GEN-LAST:event_btnAnalysisMouseClicked
    /**
     * Fills the table with the information leak findings that come in a map.
     *
     * @param evt
     */
    private void fillTableWithILFindings(JTable ilTable, Map ilMap) {
        DefaultTableModel tableModel = (DefaultTableModel) ilTable.getModel();

        Iterator keySet = ilMap.keySet().iterator();

        while (keySet.hasNext()) {
            Node key = (Node) keySet.next();
            Object[] array = new Object[]{key.toString()};
            tableModel.addRow(array);
        }
    }

    /**
     * Resets the components, whenever a new event log is is loaded, the LDG is
     * generated or a new information leak analysis is requested.
     *
     * @param evt
     */
    private void resetAnalysisPanel() {
        pAnalysisDetails.removeAll();
        pAnalysisDetails.addTab("Legend", legendLabel);
        pAnalysisDetails.revalidate();
        pAnalysisDetails.updateUI();

        nonInterferenceTable.clearSelection();
        explicitILTable.clearSelection();
        implicitILTable.clearSelection();

        DefaultTableModel niTableModel = (DefaultTableModel) nonInterferenceTable.getModel();
        while (niTableModel.getRowCount() > 0) {
            niTableModel.removeRow(0);
        }
        niTableModel.setRowCount(0);
        revalidate();

        DefaultTableModel exiTableModel = (DefaultTableModel) explicitILTable.getModel();
        while (exiTableModel.getRowCount() > 0) {
            exiTableModel.removeRow(0);
        }
        exiTableModel.setRowCount(0);
        revalidate();

        DefaultTableModel imiTableModel = (DefaultTableModel) implicitILTable.getModel();
        while (imiTableModel.getRowCount() > 0) {
            imiTableModel.removeRow(0);
        }
        imiTableModel.setRowCount(0);
        revalidate();

        System.out.println("RESET OF TABLES:");
        System.out.println("ROWS:" + nonInterferenceTable.getRowCount() + " - COL:" + nonInterferenceTable.getColumnCount());
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                //new MainGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAnalysis;
    private javax.swing.JButton btnGenerateLDG;
    private javax.swing.JButton btnImport;
    private javax.swing.ButtonGroup btngMouseMode;
    private javax.swing.JTable explicitILTable;
    private javax.swing.JFileChooser fileChooser;
    private javax.swing.JTable implicitILTable;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JLabel lblDecisionPoints;
    private javax.swing.JLabel lblDecisionPointsRes;
    private javax.swing.JLabel lblEvents;
    private javax.swing.JLabel lblEventsRes;
    private javax.swing.JLabel lblExplicitInfLeaks;
    private javax.swing.JLabel lblFile;
    private javax.swing.JLabel lblFileRes;
    private javax.swing.JLabel lblFlogNumInstances;
    private javax.swing.JLabel lblFlogNumInstancesRes;
    private javax.swing.JLabel lblFlogNumLogEvents;
    private javax.swing.JLabel lblFlogNumLogEventsRes;
    private javax.swing.JLabel lblFlogNumOriginators;
    private javax.swing.JLabel lblFlogNumOriginatorsRes;
    private javax.swing.JLabel lblFlogTotalNumEvents;
    private javax.swing.JLabel lblFlogTotalNumEventsRes;
    private javax.swing.JLabel lblImplicitInfLeaks;
    private javax.swing.JLabel lblNonInterference;
    private javax.swing.JLabel lblProcInstances;
    private javax.swing.JLabel lblProcInstancesRes;
    private javax.swing.JLabel legendLabel;
    private javax.swing.JFrame logFrame;
    private javax.swing.JTabbedPane logTabbedPane;
    private javax.swing.JPanel logTopPanel;
    private javax.swing.JList lstPlogBrowserEvents;
    private javax.swing.JList lstPlogBrowserInputs;
    private javax.swing.JList lstPlogBrowserInstances;
    private javax.swing.JList lstPlogBrowserOtherAttr;
    private javax.swing.JList lstPlogBrowserOutputs;
    private javax.swing.JMenuItem mItImportEventLog;
    private javax.swing.JMenuItem mItLogPanel;
    private javax.swing.JMenu mLog;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JTable nonInterferenceTable;
    private javax.swing.JTabbedPane pAnalysisDetails;
    private javax.swing.JPanel pAnalysisSummary;
    private javax.swing.JPanel pGraph;
    private javax.swing.JPanel pLogBrowserTab;
    private javax.swing.JPanel pLogSummary;
    private javax.swing.JPanel pLogTableTab;
    private javax.swing.JTable tLogTable;
    // End of variables declaration//GEN-END:variables
}
